package com.steven.ourcontest.app

import android.app.Application
import android.graphics.Typeface
import android.util.Log
import com.steven.ourcontest.login.helper.LoginController
import com.steven.ourcontest.net.NetConstants
import com.steven.ourcontest.net.websocket.WebSocketAndroidClient
import com.tencent.mmkv.MMKV
import org.java_websocket.handshake.ServerHandshake
import java.lang.reflect.Field


class WKApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this)
        if (LoginController.userId != 0L) {
            WebSocketAndroidClient.init(
                this,
                NetConstants.CHAT_WS_BASE_URL + LoginController.userId,
                10000
            )
            WebSocketAndroidClient.getInstance()?.connect(object: WebSocketAndroidClient.OnWebSocketOpenListener{
                override fun onOpen(handshakedata: ServerHandshake?) {
                    Log.d("WebSocket","连接成功")
                }
            })
        }
//        val mTypeface = Typeface.createFromAsset(assets, "font/字体_pop字体.ttf")
//
//        try {
//            val field: Field = Typeface::class.java.getDeclaredField("MONOSPACE")
//            field.isAccessible = true
//            field.set(null, mTypeface)
//        } catch (e: NoSuchFieldException) {
//            e.printStackTrace()
//        } catch (e: IllegalAccessException) {
//            e.printStackTrace()
//        }
    }
}